<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>医生列表</title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="../../static/css/admin.css" media="all" />
  <style>
    .layui-table-cell{
      height:auto !important;
    }
  </style>
</head>

<body>
  <div id="TMM_app">
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-tab layui-tab-brief tmm-table-tab" lay-filter="component-tabs-brief">
          <div class="layui-tab-content">
          </div>
        </div>
        <div class="layui-card-body">
          <input type="hidden" name="id" id="id" value="${id}">
          <table id="tmm-goods-table" lay-filter="tmm-goods-table" class="layui-table"></table>
        </div>
      </div>
    </div>
  </div>
  <script type="text/html" id="promoteBar">
    {{#  if(d.arrival == 0){ }}
    <a class="layui-btn layui-btn-xs" lay-event="arrival">核销</a>
    {{#  } }}
  </script>
  <script src="../../static/lib/layui/layui.js"></script>
  <script src="../../static/js/jquery.min.js"></script>
  <script>
    layui
      .config({
        base: "../../static/js/"
      })
      .extend({
        index: "index"
      })
      .use(["index", "table","laydate"], function () {
        var $ = layui.$,
          admin = layui.admin,
          view = layui.view,
          table = layui.table,
          laydate = layui.laydate,
          form = layui.form;

        table.render({
          elem: "#tmm-goods-table",
          skin: 'nob',
          size: 'lg',
          height: 'full-80',
          even: false,
          page: true,
          limit: 10,
          limits: [10, 20, 50],
          toolbar: '#toolbarDemo' ,//开启头部工具栏，并为其绑定左侧模板
          url: "${path}/t3/detail/subscribeData",
          where: {
              id:$("#id").val(),
          },
          cols: [[ //表头
            {field: 'uid', title: '预约用户ID', width:120}
            ,{field: 'name', title: '姓名', width:120}
            ,{field: 'mobile', title: '手机号', width:120}
            ,{field: 'arrival', title: '核销状态', width:120,templet:function (d) {
                if(d.arrival==1){
                  return "已核销"
                }else if(d.arrival==0){
                  return "未核销"
                }
                return d.arrival;
              }}
            ,{field: 'rewardStatus', title: '打款状态', width:120,templet:function (d) {
                if(d.rewardStatus==1){
                  return "打款中"
                }else if(d.rewardStatus==2){
                  return "已经打款"
                }else if(d.rewardStatus==3){
                  return "打款失败"
                }else if(d.rewardStatus==-1){
                  return "无需打款"
                }else if(d.rewardStatus==0){
                  return "待打款"
                }
                return d.rewardStatus;
              }}
            ,{field: 'id', title: '操作', width: 400,toolbar:'#promoteBar'}
          ]],
          text:{none:"暂无数据"},
          done: function(res, curr, count){
          }
        });

        //监听行工具事件
        table.on('tool(tmm-goods-table)', function(obj){
          var data = obj.data;

          if(obj.event === 'arrival') {
            layer.confirm('确认是否进行核销', {
              btn: ['确定', '取消']
            }, function () {
              arrival(data.uid,data.actId,1);
            });
          }
        });

        function arrival(uid,actId,status) {
          $.ajax({
            type: "post",
            url: "${path}/t3/subscribe/arrival",
            dataType: "json",
            data: {"uid":uid,"actId":actId,"status":status},
            success: function (data) {
              if(data.code != 0){
                layer.msg(data.msg, {
                  offset: '200px'
                  ,icon: 2
                  ,time: 1000
                  ,anim:4
                }, function(){});
                return;
              }
              layer.msg(data.msg, {
                offset: '200px'
                ,icon: 1
                ,time: 1000
              }, function(){
                var field = data.field;
                //执行重载
                table.reload('tmm-goods-table', {
                  where: field
                });
              });
            }
          });
        }

        //查询
        $('#query').on('click', function(){
            table.reload('tmm-goods-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    name:$("#name").val(),
                status:$("#status").val(),
                }
            }, 'data');
        });
      });
  </script>
</body>

</html>